package com.sdlogan.pbudget;

import java.util.List;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.Spinner;
import android.widget.TextView;
import android.widget.Toast;
import android.widget.AdapterView.OnItemSelectedListener;
/**
 * Class to display the expenses found in the database using a custom arrayadapter
 * @author Sean
 *
 */
public class Expenses extends Activity {

	/** Called when the activity is first created. */
	MoneyTable mt;
	List<dbPackage> expenses;
	Intent myIntent;
	ListView dataDisplay;
	DataAdapter adapter1;
	
    @Override
    /**
     * Initialize the xml and values when activity is launched
     */
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.results);
        mt = new MoneyTable(this);
        mt.open();
        expenses = mt.getExpenses();
        mt.close();
        dataDisplay = (ListView) findViewById(R.id.list);
        adapter1 = new DataAdapter(this, R.layout.data_row,expenses);
        dataDisplay.setAdapter(adapter1);
        TextView type = (TextView) findViewById(R.id.resulttype);
        type.setText("Expenses");
        
    }
    
    
    public void onClick(View v) {
    	
    }
    	/**
    	 * Inflate the options menu
    	 */
    public boolean onCreateOptionsMenu(Menu menu) {
        MenuInflater inflater = getMenuInflater();
        inflater.inflate(R.menu.mainmenu, menu);
        return true;
}
	
    /**
     * Handle items selected in the menu
     */
    public boolean onOptionsItemSelected(MenuItem item) {
		switch (item.getItemId()) {
		case R.id.home:
			Log.i("Sean","Pressed Home");
			myIntent = new Intent(Expenses.this, Main.class);
			startActivityForResult(myIntent,0);
			return true;
		case R.id.graphs:
			return true;
		case R.id.incomechart:
			Log.i("Sean","income Graph");
			myIntent = new Intent(Expenses.this,Graphs.class);
			myIntent.putExtra("type","Income");
			startActivityForResult(myIntent,0);
			return true;
		case R.id.expensechart:
			Log.i("Sean","expense graph");
			myIntent = new Intent(Expenses.this,Graphs.class);
			myIntent.putExtra("type","Expense");
			startActivityForResult(myIntent,0);
			return true;
		case R.id.expenses:
			Log.i("Sean","Pressed Expense");
			myIntent = new Intent(Expenses.this,Expenses.class);
			startActivityForResult(myIntent,0);
			return true;
		case R.id.incomes:
			Log.i("Sean","Pressed Income");
			myIntent = new Intent(Expenses.this, Incomes.class);
			startActivityForResult(myIntent,0);
			return true;
		case R.id.export:
			Log.i("Sean","Pressed Export");
			myIntent = new Intent(Expenses.this, Export.class);
			startActivityForResult(myIntent,0);
			return true;
		case R.id.newvalue:
			Log.i("Sean","Pressed New");
			return true;
		case R.id.incomenew:
			Log.i("Sean","Pressed Income");
			myIntent = new Intent(Expenses.this,SubmitForm.class);
			myIntent.putExtra("type","Income");
			startActivityForResult(myIntent,0);
			return true;
		case R.id.expensenew:
			Log.i("Sean","Pressed Expense");
			myIntent = new Intent(Expenses.this,SubmitForm.class);
			myIntent.putExtra("type","Expense");
			startActivityForResult(myIntent,0);
			return true;
		default: 
			return false;
		}
		
	}
	
}
